package ace.module.captcha.sms.core.impl.controller.graphql.client; // package

// ace.module.captcha.sms.core.impl.controller.graphql.admin;

import ace.cmp.core.model.R;
import ace.module.captcha.sms.core.impl.controller.graphql.constant.GraphqlSchemaConstants;
import ace.module.captcha.sms.core.impl.service.CaptchaSmsService;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.graphql.data.method.annotation.Argument;
import org.springframework.graphql.data.method.annotation.MutationMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author caspar
 * @date 2023/9/23 9:56
 */
@Slf4j
@AllArgsConstructor
@RestController
public class CaptchaSmsClientGraphql {
  private final CaptchaSmsService captchaSmsService;

  /**
   * 发送短信验证码
   *
   * @param captchaSmsAppId 短信验证appId
   * @param phone     手机号码
   * @return 0 is success
   */
  @MutationMapping(GraphqlSchemaConstants.Mutation.captchaSmsOpenSend)
  protected R<Void> send(
      @Valid @NotNull @Argument("captchaSmsAppId") Long captchaSmsAppId,
      @Valid @NotEmpty @Argument("phone") String phone) {

    return captchaSmsService.sendNoCode(captchaSmsAppId, phone);
  }
}
